package A1_回溯;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class LC_46全排列 {
    LinkedList<Integer> path=new LinkedList<>();
    List<List<Integer>> result=new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        int[] used=new int[nums.length];
        backtracking(nums,used);
        return result;
    }
    public void backtracking(int[] nums,int[] used){
        if(path.size()==nums.length){
            result.add(new ArrayList<>(path));
            return;
        }
        for(int i=0;i<nums.length;i++){
            if(used[i]==1)
                continue;
            used[i]=1;
            path.add(nums[i]);
            backtracking(nums,used);
            used[i]=0;
            path.removeLast();
        }
        return;
    }
}
